Merging along object hierarchies

ABSTRACT

Some embodiments of the present invention include a method for merging nodes in hierarchies and include receiving, by a database system, a request to merge a first node in a first hierarchy of a plurality of nodes into a second node, the first node in the first hierarchy having child nodes; determining, by the database system, whether the merge request violates each of a plurality of constraints, the plurality of constraints comprising circular dependency of nodes, deleted node and ordering of nodes; and re-parenting, by the database system, in response to a determination that the merge request does not violate each of the plurality of constraints, the child nodes of the first node in the first hierarchy of nodes to the second node in response to the merging of the first node into the second node.

COPYRIGHT NOTICE

A portion of the disclosure of this patent document contains materialwhich is subject to copyright protection. The copyright owner has noobjection to the facsimile reproduction by anyone of the patent documentor the patent disclosure, as it appears in the Patent and TrademarkOffice patent file or records, but otherwise reserves all copyrightrights whatsoever.

FIELD OF THE INVENTION

One or more implementations relate generally to data processing, andmore specifically for merging data organized in hierarchies.

BACKGROUND

The subject matter discussed in the background section should not beassumed to be prior art merely as a result of its mention in thebackground section. Similarly, a problem mentioned in the backgroundsection or associated with the subject matter of the background sectionshould not be assumed to have been previously recognized in the priorart. The subject matter in the background section merely representsdifferent approaches, which in and of themselves may also correspond toimplementations of the claimed inventions.

Data associated with an organization may be merged for various reasons.One example for merging is to avoid redundancy. Data may be organizedusing hierarchy and may be related to one another. Merging dataorganized in hierarchy is complex and can present many issues including,for example, consistency of data in the hierarchy before and after themerge.

BRIEF SUMMARY

For some embodiments, a method for merging nodes in hierarchies mayinclude receiving, by a database system, a request to merge a first nodein a first hierarchy of a plurality of nodes into a second node, thefirst node in the first hierarchy having child nodes; determining, bythe database system, whether the merge request violates each of aplurality of constraints, the plurality of constraints comprisingcircular dependency of nodes, deleted node and ordering of nodes; andre-parenting, by the database system, in response to a determinationthat the merge request does not violate each of the plurality ofconstraints, the child nodes of the first node in the first hierarchy ofnodes to the second node in response to the merging of the first nodeinto the second node. Other aspects and advantages of the presentinvention can be seen on review of the drawings, the detaileddescription and the claims, which follow.

BRIEF DESCRIPTION OF THE DRAWINGS

The included drawings are for illustrative purposes and serve only toprovide examples of possible structures and process steps for thedisclosed techniques. These drawings in no way limit any changes in formand detail that may be made to embodiments by one skilled in the artwithout departing from the spirit and scope of the disclosure.

FIG. 1 is example diagram of a computing system that may be used withsome embodiments.

FIG. 2 is an example diagram of a network environment that may be usedwith some embodiments.

FIGS. 3A-3J are example diagrams showing hierarchies that may beresulted from merging of a victim node to a master node, in accordancewith some embodiments.

FIGS. 4A-4B are example diagrams showing soft delete node in a merge, inaccordance with some embodiments.

FIG. 5 shows an example implementation of a merge module, in accordancewith some embodiments.

FIG. 6A shows a flowchart of an example process for verifying therequirements to merge nodes in hierarchies, in accordance with someembodiments.

FIG. 6B shows a flowchart of an example process for merging nodes afterthe requirements are satisfied, in accordance with some embodiments.

FIG. 7 shows example scripts written in PL/SQL that may be used to mergenodes in hierarchies, in accordance with some embodiments.

FIG. 8A shows a system diagram illustrating architectural components ofan applicable environment, in accordance with some embodiments.

FIG. 8B shows a system diagram further illustrating architecturalcomponents of an applicable environment, in accordance with someembodiments.

FIG. 9 shows a system diagram illustrating the architecture of amultitenant database environment, in accordance with some embodiments.

FIG. 10 shows a system diagram further illustrating the architecture ofa multi-tenant database environment, in accordance with someembodiments.

DETAILED DESCRIPTION

Various implementations described or referenced herein are directed todifferent systems, apparatus, methods and computer-readable storagemedia for merging data organized in hierarchies. In the followingdescription, a hierarchy may include one or more levels, with each levelhaving one or more nodes. The hierarchies and the nodes may beassociated with a database system. The term “node” is used in thedescription to generically refer to a data entity in a hierarchy and itsrelationship with another data entity in the hierarchy. For example, anode can be a record, an account or a business object. A node to bemerged to another node may be referred to as a victim node. A node thatthe victim node is merged to may be referred to as a master node. Arequest to merge a victim node to a master node may be received via auser interface or an application programming interface (API). There maybe one or more victim nodes in a merge request.

The systems, apparatus, methods and computer-readable storage media formerging data organized in hierarchies will be described with referenceto example embodiments. These examples are being provided solely to addcontext and aid in the understanding of the present disclosure. It willthus be apparent to one skilled in the art that the techniques describedherein may be practiced without some or all of these specific details.In other instances, well known process steps have not been described indetail in order to avoid unnecessarily obscuring the present disclosure.Other applications are possible, such that the following examples shouldnot be taken as definitive or limiting either in scope or setting.

In the following detailed description, references are made to theaccompanying drawings, which form a part of the description and in whichare shown, by way of illustration, specific embodiments. Although theseembodiments are described in sufficient detail to enable one skilled inthe art to practice the disclosure, it is understood that these examplesare not limiting, such that other embodiments may be used and changesmay be made without departing from the spirit and scope of thedisclosure.

As used herein, the term “multi-tenant database system” refers to thosesystems in which various elements of hardware and software of thedatabase system may be shared by one or more customers. For example, agiven application server may simultaneously process requests for a greatnumber of customers, and a given database table may store rows for apotentially much greater number of customers.

The described subject matter may be implemented in the context of anycomputer-implemented system, such as a software-based system, a databasesystem, a multi-tenant environment, or the like. Moreover, the describedsubject matter may be implemented in connection with two or moreseparate and distinct computer-implemented systems that cooperate andcommunicate with one another. One or more embodiments may be implementedin numerous ways, including as a process, an apparatus, a system, adevice, a method, a computer readable medium such as a computer readablestorage medium containing computer readable instructions or computerprogram code, or as a computer program product comprising a computerusable medium having a computer readable program code embodied therein.

The disclosed embodiments may include a method for merging nodes inhierarchies and include receiving, by a database system, a request tomerge a first node in a first hierarchy of a plurality of nodes into asecond node, the first node in the first hierarchy having child nodes;determining, by the database system, whether the merge request violateseach of a plurality of constraints, the plurality of constraintscomprising circular dependency of nodes, deleted node and ordering ofnodes; and re-parenting, by the database system, in response to adetermination that the merge request does not violate each of theplurality of constraints, the child nodes of the first node in the firsthierarchy of nodes to the second node in response to the merging of thefirst node into the second node.

The disclosed embodiments may include an apparatus for merging nodes inhierarchies and include a processor, and one or more stored sequences ofinstructions which, when executed by the processor, cause the processorto receive a request to merge a first node in a first hierarchy of aplurality of nodes into a second node, the first node in the firsthierarchy having child nodes; determine whether the merge requestviolates each of a plurality of constraints, the plurality ofconstraints comprising circular dependency of nodes, deleted node andordering of nodes; and re-parent, in response to a determination thatthe merge request does not violate each of the plurality of constraints,the child nodes of the first node in the first hierarchy of nodes to thesecond node in response to the merging of the first node into the secondnode.

The disclosed embodiments may include a machine-readable medium carryingone or more sequences of instructions for merging nodes in hierarchies,which instructions, when executed by one or more processors, may causethe one or more processors to receive a request to merge a first node ina first hierarchy of a plurality of nodes into a second node, the firstnode in the first hierarchy having child nodes; determine whether themerge request violates each of a plurality of constraints, the pluralityof constraints comprising circular dependency of nodes, deleted node andordering of nodes; and re-parent, in response to a determination thatthe merge request does not violate each of the plurality of constraints,the child nodes of the first node in the first hierarchy of nodes to thesecond node in response to the merging of the first node into the secondnode.

While one or more implementations and techniques are described withreference to an embodiment in which merging operations are implementedin a system having an application server providing a front end for anon-demand database service capable of supporting multiple tenants, theone or more implementations and techniques are not limited tomulti-tenant databases nor deployment on application servers.Embodiments may be practiced using other database architectures, i.e.,ORACLE®, DB2® by IBM and the like without departing from the scope ofthe embodiments claimed. Likewise, embodiments may be practiced incloud-based storage systems that make up an on-demand computing platformsuch as those provided by Amazon® Web Services.

Any of the above embodiments may be used alone or together with oneanother in any combination. The one or more implementations encompassedwithin this specification may also include embodiments that are onlypartially mentioned or alluded to or are not mentioned or alluded to atall in this brief summary or in the abstract. Although variousembodiments may have been motivated by various deficiencies with theprior art, which may be discussed or alluded to in one or more places inthe specification, the embodiments do not necessarily address any ofthese deficiencies. In other words, different embodiments may addressdifferent deficiencies that may be discussed in the specification. Someembodiments may only partially address some deficiencies or just onedeficiency that may be discussed in the specification, and someembodiments may not address any of these deficiencies.

The described subject matter may be implemented in the context of anycomputer-implemented system, such as a software-based system, a databasesystem, a multi-tenant environment, or the like. Moreover, the describedsubject matter may be implemented in connection with two or moreseparate and distinct computer-implemented systems that cooperate andcommunicate with one another. One or more implementations may beimplemented in numerous ways, including as a process, an apparatus, asystem, a device, a method, a computer readable medium such as acomputer readable storage medium containing computer readableinstructions or computer program code, or as a computer program productcomprising a computer usable medium having a computer readable programcode embodied therein.

In general, businesses use a CRM (Customer Relationship Management)system (also referred to as a database system or system) to managebusiness relationships and information associated with the businessrelationship. For example, this may include customer and prospectcontact information, accounts, leads, and opportunities in one centrallocation. The information may be stored in a database as objects. Forexample, the CRM system may include “account” object, “contact” objectand “opportunities” object.

The “account” object may include information about an organization orperson (such as customers, competitors, and partners) involved with aparticular business. The “contact” object may include contactinformation, where each contact may be an individual associated with an“account”. The “opportunities” object includes information about a saleor a pending deal. Each object may be associated with fields. Forexample, the “accounts” object may include fields such as “company”,“zip”, “phone number”, “email address”, etc. The “contact” object mayinclude fields such as “first name”, “last name”, “phone number”,“accountID”, etc. The “accountID” field of the “contact” object may bethe ID of the account that is the parent of the contact. The“opportunity” object may include fields such as “amount”, “accountID”,etc. The “accountID” field of the “opportunity” object may be the ID ofthe account that is associated with the opportunity. Each field may beassociated with a field value. For example, a field value for the “zip”field may be “94105”. For some embodiments, the hierarchies describedherein may be related to an object and the nodes in the hierarchies maybe related to a field in the object. For some embodiments, the systems,methods, apparatus and computer-readable storage media described hereinprovide ways of managing the hierarchies regardless of the fields used.

FIG. 1 is a diagram of an example computing system that may be used withsome embodiments of the present invention. The computing system 102 maybe used by a user to log into a server computer system to enable theserver computer system to merge data organized in hierarchies and toprevent hierarchy inconsistency in the merged result.

The computing system 102 is only one example of a suitable computingsystem, such as a mobile computing system, and is not intended tosuggest any limitation as to the scope of use or functionality of thedesign. Neither should the computing system 102 be interpreted as havingany dependency or requirement relating to any one or combination ofcomponents illustrated. The design is operational with numerous othergeneral purpose or special purpose computing systems. Examples ofwell-known computing systems, environments, and/or configurations thatmay be suitable for use with the design include, but are not limited to,personal computers, server computers, hand-held or laptop devices,multiprocessor systems, microprocessor-based systems, set top boxes,programmable consumer electronics, mini-computers, mainframe computers,distributed computing environments that include any of the above systemsor devices, and the like. For example, the computing system 102 may beimplemented as a mobile computing system such as one that is configuredto run with an operating system (e.g., iOS) developed by Apple Inc. ofCupertino, Calif. or an operating system (e.g., Android) that isdeveloped by Google Inc. of Mountain View, Calif.

Some embodiments of the present invention may be described in thegeneral context of computing system executable instructions, such asprogram modules, being executed by a computer. Generally, programmodules include routines, programs, objects, components, datastructures, etc. that performs particular tasks or implement particularabstract data types. Those skilled in the art can implement thedescription and/or figures herein as computer-executable instructions,which can be embodied on any form of computing machine readable mediadiscussed below.

Some embodiments of the present invention may also be practiced indistributed computing environments where tasks are performed by remoteprocessing devices that are linked through a communications network. Ina distributed computing environment, program modules may be located inboth local and remote computer storage media including memory storagedevices.

Referring to FIG. 1, the computing system 102 may include, but are notlimited to, a processing unit 120 having one or more processing cores, asystem memory 130, and a system bus 121 that couples various systemcomponents including the system memory 130 to the processing unit 120.The system bus 121 may be any of several types of bus structuresincluding a memory bus or memory controller, a peripheral bus, and alocal bus using any of a variety of bus architectures. By way ofexample, and not limitation, such architectures include IndustryStandard Architecture (ISA) bus, Micro Channel Architecture (MCA) bus,Enhanced ISA (EISA) bus, Video Electronics Standards Association (VESA)locale bus, and Peripheral Component Interconnect (PCI) bus also knownas Mezzanine bus.

The computing system 102 typically includes a variety of computerreadable media. Computer readable media can be any available media thatcan be accessed by computing system 102 and includes both volatile andnonvolatile media, removable and non-removable media. By way of example,and not limitation, computer readable media may store information suchas computer readable instructions, data structures, program modules orother data. Computer storage media include, but are not limited to, RAM,ROM, EEPROM, flash memory or other memory technology, CD-ROM, digitalversatile disks (DVD) or other optical disk storage, magnetic cassettes,magnetic tape, magnetic disk storage or other magnetic storage devices,or any other medium which can be used to store the desired informationand which can be accessed by computing system 102. Communication mediatypically embodies computer readable instructions, data structures, orprogram modules.

The system memory 130 may include computer storage media in the form ofvolatile and/or nonvolatile memory such as read only memory (ROM) 131and random access memory (RAM) 132. A basic input/output system (BIOS)133, containing the basic routines that help to transfer informationbetween elements within computing system 102, such as during start-up,is typically stored in ROM 131. RAM 132 typically contains data and/orprogram modules that are immediately accessible to and/or presentlybeing operated on by processing unit 120. By way of example, and notlimitation, FIG. 1 also illustrates operating system 134, applicationprograms 135, other program modules 136, and program data 137.

The computing system 102 may also include other removable/non-removablevolatile/nonvolatile computer storage media. By way of example only,FIG. 1 also illustrates a hard disk drive 141 that reads from or writesto non-removable, nonvolatile magnetic media, a magnetic disk drive 151that reads from or writes to a removable, nonvolatile magnetic disk 152,and an optical disk drive 155 that reads from or writes to a removable,nonvolatile optical disk 156 such as, for example, a CD ROM or otheroptical media. Other removable/non-removable, volatile/nonvolatilecomputer storage media that can be used in the exemplary operatingenvironment include, but are not limited to, USB drives and devices,magnetic tape cassettes, flash memory cards, digital versatile disks,digital video tape, solid state RAM, solid state ROM, and the like. Thehard disk drive 141 is typically connected to the system bus 121 througha non-removable memory interface such as interface 140, and magneticdisk drive 151 and optical disk drive 155 are typically connected to thesystem bus 121 by a removable memory interface, such as interface 150.

The drives and their associated computer storage media discussed aboveand illustrated in FIG. 1, provide storage of computer readableinstructions, data structures, program modules and other data for thecomputing system 102. In FIG. 1, for example, hard disk drive 141 isillustrated as storing operating system 144, application programs 145,other program modules 146, and program data 147. Note that thesecomponents can either be the same as or different from operating system134, application programs 135, other program modules 136, and programdata 137. The operating system 144, the application programs 145, theother program modules 146, and the program data 147 are given differentnumeric identification here to illustrate that, at a minimum, they aredifferent copies.

A user may enter commands and information into the computing system 102through input devices such as a keyboard 162, a microphone 163, and apointing device 161, such as a mouse, trackball or touch pad or touchscreen. Other input devices (not shown) may include a joystick, gamepad, scanner, or the like. These and other input devices are oftenconnected to the processing unit 120 through a user input interface 160that is coupled with the system bus 121, but may be connected by otherinterface and bus structures, such as a parallel port, game port or auniversal serial bus (USB). A monitor 191 or other type of displaydevice is also connected to the system bus 121 via an interface, such asa video interface 190. In addition to the monitor, computers may alsoinclude other peripheral output devices such as speakers 197 and printer196, which may be connected through an output peripheral interface 190.

The computing system 102 may operate in a networked environment usinglogical connections to one or more remote computers, such as a remotecomputer 180. The remote computer 180 may be a personal computer, ahand-held device, a server, a router, a network PC, a peer device orother common network node, and typically includes many or all of theelements described above relative to the computing system 102. Thelogical connections depicted in FIG. 1 include a local area network(LAN) 171 and a wide area network (WAN) 173, but may also include othernetworks. Such networking environments are commonplace in offices,enterprise-wide computer networks, intranets and the Internet.

FIG. 1 includes a local area network (LAN) 171 and a wide area network(WAN) 173, but may also include other networks. Such networkingenvironments are commonplace in offices, enterprise-wide computernetworks, intranets and the Internet.

When used in a LAN networking environment, the computing system 102 maybe connected to the LAN 171 through a network interface or adapter 170.When used in a WAN networking environment, the computing system 102typically includes a modem 172 or other means for establishingcommunications over the WAN 173, such as the Internet. The modem 172,which may be internal or external, may be connected to the system bus121 via the user-input interface 160, or other appropriate mechanism. Ina networked environment, program modules depicted relative to thecomputing system 102, or portions thereof, may be stored in a remotememory storage device. By way of example, and not limitation, FIG. 1illustrates remote application programs 185 as residing on remotecomputer 180. It will be appreciated that the network connections shownare exemplary and other means of establishing a communications linkbetween the computers may be used.

It should be noted that some embodiments of the present invention may becarried out on a computing system such as that described with respect toFIG. 1. However, some embodiments of the present invention may becarried out on a server, a computer devoted to message handling,handheld devices, or on a distributed system in which different portionsof the present design may be carried out on different parts of thedistributed computing system.

Another device that may be coupled with the system bus 121 is a powersupply such as a battery or a Direct Current (DC) power supply) andAlternating Current (AC) adapter circuit. The DC power supply may be abattery, a fuel cell, or similar DC power source needs to be rechargedon a periodic basis. The communication module (or modem) 172 may employa Wireless Application Protocol (WAP) to establish a wirelesscommunication channel. The communication module 172 may implement awireless networking standard such as Institute of Electrical andElectronics Engineers (IEEE) 802.11 standard, IEEE std. 802.11-1999,published by IEEE in 1999.

Examples of mobile computing systems may be a laptop computer, a tabletcomputer, a Netbook, a smart phone, a personal digital assistant, orother similar device with on board processing power and wirelesscommunications ability that is powered by a Direct Current (DC) powersource that supplies DC voltage to the mobile computing system and thatis solely within the mobile computing system and needs to be rechargedon a periodic basis, such as a fuel cell or a battery.

FIG. 2 shows a diagram of an example network environment that may beused with some embodiments of the present invention. Network environment400 includes user computing systems 205 and 212. One or more of the usercomputing systems 205 and 212 may be a mobile computing system. The usercomputing systems 205 and 212 may be connected to the network 250 via acellular connection or via a Wi-Fi router (not shown). The network 250may be the Internet. The user computing systems 205 and 212 may becoupled with server computing system 255 via the network 250.

The user computing systems 205 may include application module 208. Auser may use the user computing system 205 and the application module208 to connect to and communicate with the server computing system 255and login to application 257 (e.g., a salesforce.com® application). Theserver computing system 255 may be coupled with database 270. The servercomputing system 255 may be associated with an entity (e.g.,salesforce.com®). The user computing system 205 may be used to issuemerge requests via a user interface or an API.

FIGS. 3A-3J are example diagrams showing merging of victim nodes tomaster nodes, in accordance with some embodiments. In general, a requestto merge one or more victim nodes to a master node may only be allowedto proceed if a number of constraints are met. As will be described, theconstraints may include circular dependency constraint, deleted nodeconstraint and ordering of nodes constraint. For some embodiments, whena request is allowed to proceed, the master node may remain as an activenode in its hierarchy after the merge while the one or more victim nodesmay be deleted from the system. If the master node has a parent beforethe merge, then the master node has the same parent after the merge,unless a new parent ID is provided with the merge request. If the masternode has no parent before the merge, then the master node also has noparent after the merger, unless a new parent ID is provided with themerge. Further, when a victim node is deleted, its child nodes may bere-parented and become the child nodes of the master node. This may beimplemented by updating each of the child nodes with a parentidentification (ID) corresponding to the ID of the master node. If thevictim node has no children, no re-parenting may be necessary.

Referring to FIG. 3A, three hierarchies 300, 305 and 310 are to bemerged based on their respective victim and master nodes. The hierarchy300 includes a victim node 302, its parent node 301, and its child node303. The hierarchy 310 includes a victim node 312, its parent node 311,and its child node 313. The hierarchy 305 includes a master node 307,its parent node 306, and its child node 305. The directional line 304connects the child node 303 of the hierarchy 300 to the parent node 306of the hierarchy 305 in the direction of parent-child relationship.Similarly, the directional line 309 connects the child node 308 of thehierarchy 305 to the parent node 311 of the hierarchy 310 in thedirection of parent-child relationship.

Referring to FIG. 3B, when the victim nodes 302 and 312 are merged tothe master node 307, the child node 303 of the victim node 302 and thechild node 313 of the victim node 312 become children of the master node307 in the hierarchy 314. The victim nodes 302 and 312 (shown as dottedlines) may then be deleted from the system. As shown by directional line304, because the child node 303 is also a parent of the parent node 306,the hierarchy 314 has circular dependency. For some embodiments, themerging of the victim node and the master node may be blocked if themerging results in a hierarchy that includes circular dependency. Basedon the resulting circular dependency in the hierarchy 314, the mergingrequest may be blocked. The circular dependency of the nodes is aconstraint that the merge request has to satisfy to be allowed toproceed.

Referring to FIG. 3C, the hierarchy 315 includes a victim node 316 andits child nodes 317 and 318. The hierarchy 320 includes a master node322, its parent node 321 and its child nodes 323 and 324. Directionalline 325 shows that the child node 318 of the hierarchy 315 is also aparent of the parent node 321 of the hierarchy 320.

Referring to FIG. 3D, when the victim node 316 is merged to the masternode 322, the child nodes 317 and 318 of the victim node 316 becomechildren of the master node 322 in the hierarchy 326. The victim node316 (shown as dotted lines) may then be deleted from the system.However, as shown by line 325, because the child node 318 is also aparent of the parent node 321, the hierarchy 326 has circulardependency. Based on the resulting circular dependency, the mergingrequest may be blocked. This may be related to the circular dependencyconstraint.

Referring to FIG. 3E, the hierarchy 330 includes a master node 331 andits child nodes 332 and 333. The hierarchy 335 includes a victim node337, its parent node 336 and its child nodes 338 and 339. Thedirectional line 340 shows that the child node 333 of the hierarchy 330is also a parent of the parent node 336 of the hierarchy 335.

Referring to FIG. 3F, when the victim node 337 is merged to the masternode 331, the child nodes 338 and 339 of the victim node 337 becomechildren of the master node 331 in the hierarchy 340. The victim node337 (shown as dotted lines) may then be deleted from the system. Sincethe hierarchy 340 does not show that the master node 331 having a parentthat is a descendant of any of the merged nodes before or after themerging, there is no circular dependency. As such, the merging of thevictim node 337 to the master node 331 may be allowed to proceed.

Referring to FIG. 3G, the hierarchy 345 includes a victim node 352, itsparent node 346, and its child node 348. The victim node 347 alsoincludes another child node 349 which is designated as a master node(referred to as master node 349). In this example, if the merging isallowed to proceed, the victim node 347 would be deleted. However,because the victim node 347 is a parent of the master node 349, deletingthe victim node 347 would cause the master node 349 to have a deletednode as a parent. For some embodiments, the merging of the victim nodeand the master node may be blocked if the master node is a child nodeand the victim node is a parent node. The ordering of the victim nodeand the master node is another constraint that the merge request has tosatisfy to be allowed to proceed.

Referring to FIG. 3H, the hierarchy 350 includes a victim node 352, itsparent node 351, its child nodes 353 and 354, its grandchild nodes 355and 356 from the child node 354, its great grandchild node 357 from thegrandchild node 355, and its great-great grandchild nodes 358 and 359from the great grandchild node 357. The great grandchild node 357 isalso designated as the master node (referred to as master node 357). Forsome embodiments, a master node should not be a descendant of any of thevictim nodes in a merge request. Verification may be performed toconfirm that the master node is not a descendant of a victim node beforeany merging operation is performed. In this example, the hierarchy 350shows that the master node 357 is a great grandchild of the victim node352. As such, the merging request may be blocked. This may be related tothe ordering of nodes constraint.

Referring to FIG. 3I, even when the victim node 352 is merged to themaster node 357, the merging request may still be blocked due tocircular dependency. For example, the child nodes 353 and 354 of thevictim node 352 become children of the master node 357 in the hierarchy360. The grand child nodes 355 and 356 remain with the child node 354.The victim node 352 (shown as dotted lines) may then be deleted from thesystem. However, as shown by directional line 362, because thegrandchild node 355 is also a parent of the master node 357, thehierarchy 360 has circular dependency. Based on the resulting circulardependency, the merging request may be blocked. This may be related tothe circular dependency constraint.

FIG. 3J shows an example of a circular dependency of a hierarchy beforemerging, in accordance with some embodiments. In this example, thehierarchy 370 includes a master node 374 and its parent node 372. Thehierarchy 380 includes the victim node 384, its parent node 382 and itschild nodes 386 and 388. The child node 388 is also a parent node of thevictim node 384 (shown as directional line 376). For some embodiments,the hierarchies associated with the master node and the victim node maybe evaluated for circular dependency prior to any merging operation. Ifthe circular dependency exists in either or both of the hierarchies, themerging request may be blocked. This may be related to the circulardependency constraint.

FIG. 4A shows an example of a soft delete node, in accordance with someembodiments. In this example, the hierarchy 400 includes a master node410, its parent node 405, and its child node 415. The hierarchy 450includes the victim node 460, its parent node 455 and its child node465. The victim node 460 also has another child node 470 which, eventhough has been deleted, still remains in the temporary delete or softdelete status (shown as dotted lines). For some embodiments, atemporarily or soft deleted node may be undeleted to return to a normalor active status. However, a permanently deleted node may not beundeleted.

FIG. 4B shows an example of incorporating a soft delete node in a merge,in accordance with some embodiments. When the victim node 460 is mergedwith the master node 410, the child node 465 becomes the child node ofthe master node 410. For some embodiments, the child node 470 may alsobe linked to the master node 410 as a pseudo child node even though itis in the soft delete status. When the child node 470 is laterundeleted, it becomes an active child node of the master node 410,instead of being an orphan node of the deleted victim node 460. FIGS. 4Aand 4B also shows a scenario of merging a parented victim node 460 and aparented master node 410, with the master node 410 retaining its parentnode 405 after the merging operation, as shown in the hierarchy 480.

It may be possible that both the victim node and the master node areactive nodes at the time the merge request is initiated. However,subsequently, one or both of the victim node and master node may bedeleted from the system. For some embodiments, verification may beperformed prior to any merging operations to confirm that both themaster node and the victim node are still active nodes. If one or bothof the victim node and master node is deleted, the merge request may beblocked. The deleted node is another constraint that the merge requesthas to satisfy to be allowed to proceed.

For some embodiments, a merge request may also include a new parent IDfor the master node. In such scenario, verification may be performed toconfirm that that node associated with the new parent ID is an activenode, and not a deleted node, before any merging operation is performed.It is possible that when the request is initiated, the node associatedwith the new parent ID is an active node; however, it may also bepossible that the same node is deleted before the merge operation. Ifthe new parent ID is verified to be associated with a node that has beendeleted, the merge request may be blocked because of a potential orphanmaster node. This may be related to the deleted node constraint.

For some embodiments, verification may be performed to confirm that thenode associated with the new parent ID is not a descendant node of themaster node. If the new parent ID is verified to be associated with adescendant node, the merge request may be blocked because of potentialcircular dependency. This may be related to the circular dependencyconstraint. This may also be related to the ordering of nodesconstraint.

FIG. 5 shows an example implementation of a merge module, in accordancewith some embodiments. Merge module 500 may be used to receive mergerequests and merge a victim node to a master node. The merge module 500may include a circular dependency verification module 510 configured toverify whether a hierarchy associated with the master node or the victimnode includes circular dependency. The circular dependency verificationmodule 510 may also be configured to verify whether a merge of thevictim node to the master node may result in a hierarchy that includescircular dependency. If circular dependency is identified by thecircular dependency verification module 510, the merge module 500 mayblock the merge request.

The merge module 500 may include an active node verification module 515configured to verify whether a node is active or deleted. This mayinclude verifying whether both of the master node and the victim nodeare active nodes. This may also include verifying whether the parentnode associated with the new parent ID included in the merge request isan active node. If any of these nodes is identified by the active nodeverification module 515 as a non-active node (or deleted node), themerge module 500 may block the merge request.

The merge module 500 may include a re-parenting module 520 configured tore-parent child nodes of a victim node to a master node. Re-parenting achild node may retain the parenting relationship of all descendant nodesof the child node. The re-parenting module 520 may also be configured tore-parent the master node if the merge request includes a new parent IDfor the master node.

The merge module 500 may include a soft delete verification module 525configured to verify whether a victim node is associated with any softdelete child node. If a soft delete child node is identified, the softdelete child node may be re-parented to the master node even though itis not an active node. An example is described with FIGS. 4A and 4B. Themerge module 500 may include a victim node removal module 530 configuredto remove or delete a victim node from the system when a merge requestis allowed to proceed. Although not shown, the merge module 500 mayinclude other modules to enable performing operations to complete amerge request.

FIG. 6A shows a flowchart of an example process for verifying therequirements to merge nodes in hierarchies, in accordance with someembodiments. The process may start at block 605 where the merge requestis received. A master node and a victim node may be included in themerge request. At block 610, verification may be performed to determinewhether a hierarchy associated with the master node or the victim nodeincludes circular dependency. If circular dependency exists, the mergerequest may be blocked for failing the circular dependency constraint.If not, the process flows to block 615 where verification may beperformed to determine if the master node is a descendant of the victimnode in a hierarchy. If that is the case, the merge request may beblocked for failing the ordering of nodes constraint. If not, theprocess may flow to block 620 where verification may be performed todetermine whether the merge request includes a new parent ID for themaster node. If a new parent ID is included, verification may beperformed to determine if the node associated with the new parent ID isa descendant node of the master node. If that is the case, the mergerequest may be blocked for failing the circular dependency constraint.If not, the process may flow to block 625 where verification may beperformed to determine whether the new parent ID included in the mergerequest is associated with a deleted node. If that is the case, themerge request may be blocked for failing the deleted node constraint. Ifnot, the process may flow to block 630.

At block 630, verification may be performed to determine whether eitherof the master node or the victim node is a deleted node. If that is thecase, the merge request may be blocked for failing the deleted nodeconstraint. If not, the process may flow to block 635 where verificationmay be performed to determine whether the merge of the victim node tothe master node may result in a hierarchy that includes circulardependency. If that is the case, the merge request may be blocked forfailing the circular dependency constraint. For example, when there-parenting of the child nodes of the victim node to the master nodegenerates circular dependency, the merge process may be stopped and anyre-parenting that has been performed may be reversed. For someembodiments, a merge request may need to satisfy each of the circulardependency constraint, deleted node constraint, and ordering of nodesconstraint to be allowed to proceed.

FIG. 6B shows a flowchart of an example process for merging nodes afterthe requirements are satisfied, in accordance with some embodiments. Theprocess 650 may start at block 655 where child nodes of a victim nodeare re-parented to the master node. If the victim node has no childnode, then no re-parenting may be necessary. At block 660, if it isverified that the victim node has a soft delete child node, that childnode may also be re-parented to the master node. At block 665, if themerge request includes a new parent ID for the master node, the masternode may be re-parented to the node associated with the new parent ID.If the merge request does not include a new parent ID for the masternode, then the parent information of the master node may remain the sameas before the merge. For example, if the master node was a stand-alonenode with no parent before the merge, then the master node remains as astand-alone node after the merge. If the master node had a parent beforethe merge, then that parent remains as the parent of the master nodeafter the merge. At block 670, the victim node may be deleted from thesystem.

For some embodiments, the process of merging the victim node to themaster node described above may be implemented using one or more ofPL/SQL (Procedure Language/Structured Query Language) and Java of OracleCorporation. PL/SQL is a procedure extension for SQL and the Oraclerelational database. Java is general-purpose programming languagedesigned to have as few implementation dependencies as possible and canrun on all platforms that support Java without the need forrecompilation. Using a record as a node, FIG. 7 shows some examplescripts in PL/SQL to set parent for records, get child records, and getancestors for record.

FIG. 8A shows a system diagram 800 illustrating architectural componentsof an on-demand service environment, in accordance with someembodiments. A client machine located in the cloud 804 (or Internet) maycommunicate with the on-demand service environment via one or more edgerouters 808 and 812. The edge routers may communicate with one or morecore switches 820 and 824 via firewall 816. The core switches maycommunicate with a load balancer 828, which may distribute server loadover different pods, such as the pods 840 and 844. The pods 840 and 844,which may each include one or more servers and/or other computingresources, may perform data processing and other operations used toprovide on-demand services. Communication with the pods may be conductedvia pod switches 832 and 836. Components of the on-demand serviceenvironment may communicate with a database storage system 856 via adatabase firewall 848 and a database switch 852.

As shown in FIGS. 8A and 8B, accessing an on-demand service environmentmay involve communications transmitted among a variety of differenthardware and/or software components. Further, the on-demand serviceenvironment 800 is a simplified representation of an actual on-demandservice environment. For example, while only one or two devices of eachtype are shown in FIGS. 8A and 8B, some embodiments of an on-demandservice environment may include anywhere from one to many devices ofeach type. Also, the on-demand service environment need not include eachdevice shown in FIGS. 8A and 8B, or may include additional devices notshown in FIGS. 8A and 8B.

Moreover, one or more of the devices in the on-demand serviceenvironment 800 may be implemented on the same physical device or ondifferent hardware. Some devices may be implemented using hardware or acombination of hardware and software. Thus, terms such as “dataprocessing apparatus,” “machine,” “server” and “device” as used hereinare not limited to a single hardware device, but rather include anyhardware and software configured to provide the described functionality.

The cloud 804 is intended to refer to a data network or plurality ofdata networks, often including the Internet. Client machines located inthe cloud 804 may communicate with the on-demand service environment toaccess services provided by the on-demand service environment. Forexample, client machines may access the on-demand service environment toretrieve, store, edit, and/or process information.

In some embodiments, the edge routers 808 and 812 route packets betweenthe cloud 804 and other components of the on-demand service environment800. The edge routers 808 and 812 may employ the Border Gateway Protocol(BGP). The BGP is the core routing protocol of the Internet. The edgerouters 808 and 812 may maintain a table of IP networks or ‘prefixes’which designate network reachability among autonomous systems on theInternet.

In one or more embodiments, the firewall 816 may protect the innercomponents of the on-demand service environment 800 from Internettraffic. The firewall 816 may block, permit, or deny access to the innercomponents of the on-demand service environment 800 based upon a set ofrules and other criteria. The firewall 816 may act as one or more of apacket filter, an application gateway, a stateful filter, a proxyserver, or any other type of firewall.

In some embodiments, the core switches 820 and 824 are high-capacityswitches that transfer packets within the on-demand service environment800. The core switches 820 and 824 may be configured as network bridgesthat quickly route data between different components within theon-demand service environment. In some embodiments, the use of two ormore core switches 820 and 824 may provide redundancy and/or reducedlatency.

In some embodiments, the pods 840 and 844 may perform the core dataprocessing and service functions provided by the on-demand serviceenvironment. Each pod may include various types of hardware and/orsoftware computing resources. An example of the pod architecture isdiscussed in greater detail with reference to FIG. 8B.

In some embodiments, communication between the pods 840 and 844 may beconducted via the pod switches 832 and 836. The pod switches 832 and 836may facilitate communication between the pods 840 and 844 and clientmachines located in the cloud 804, for example via core switches 820 and824. Also, the pod switches 832 and 836 may facilitate communicationbetween the pods 840 and 844 and the database storage 856.

In some embodiments, the load balancer 828 may distribute workloadbetween the pods 840 and 844. Balancing the on-demand service requestsbetween the pods may assist in improving the use of resources,increasing throughput, reducing response times, and/or reducingoverhead. The load balancer 828 may include multilayer switches toanalyze and forward traffic.

In some embodiments, access to the database storage 856 may be guardedby a database firewall 848. The database firewall 848 may act as acomputer application firewall operating at the database applicationlayer of a protocol stack. The database firewall 848 may protect thedatabase storage 856 from application attacks such as structure querylanguage (SQL) injection, database rootkits, and unauthorizedinformation disclosure.

In some embodiments, the database firewall 848 may include a host usingone or more forms of reverse proxy services to proxy traffic beforepassing it to a gateway router. The database firewall 848 may inspectthe contents of database traffic and block certain content or databaserequests. The database firewall 848 may work on the SQL applicationlevel atop the TCP/IP stack, managing applications' connection to thedatabase or SQL management interfaces as well as intercepting andenforcing packets traveling to or from a database network or applicationinterface.

In some embodiments, communication with the database storage system 856may be conducted via the database switch 852. The multi-tenant databasesystem 856 may include more than one hardware and/or software componentsfor handling database queries. Accordingly, the database switch 852 maydirect database queries transmitted by other components of the on-demandservice environment (e.g., the pods 840 and 844) to the correctcomponents within the database storage system 856. In some embodiments,the database storage system 856 is an on-demand database system sharedby many different organizations. The on-demand database system mayemploy a multi-tenant approach, a virtualized approach, or any othertype of database approach. An on-demand database system is discussed ingreater detail with reference to FIGS. 9 and 10.

FIG. 8B shows a system diagram illustrating the architecture of the pod844, in accordance with one embodiment. The pod 844 may be used torender services to a user of the on-demand service environment 800. Insome embodiments, each pod may include a variety of servers and/or othersystems. The pod 844 includes one or more content batch servers 864,content search servers 868, query servers 872, file force servers 876,access control system (ACS) servers 880, batch servers 884, and appservers 888. Also, the pod 844 includes database instances 890, quickfile systems (QFS) 892, and indexers 894. In one or more embodiments,some or all communication between the servers in the pod 844 may betransmitted via the switch 836.

In some embodiments, the application servers 888 may include a hardwareand/or software framework dedicated to the execution of procedures(e.g., programs, routines, scripts) for supporting the construction ofapplications provided by the on-demand service environment 800 via thepod 844. Some such procedures may include operations for providing theservices described herein. The content batch servers 864 may requestsinternal to the pod. These requests may be long-running and/or not tiedto a particular customer. For example, the content batch servers 864 mayhandle requests related to log mining, cleanup work, and maintenancetasks.

The content search servers 868 may provide query and indexer functions.For example, the functions provided by the content search servers 868may allow users to search through content stored in the on-demandservice environment. The Fileforce servers 876 may manage requestsinformation stored in the Fileforce storage 878. The Fileforce storage878 may store information such as documents, images, and basic largeobjects (BLOBs). By managing requests for information using theFileforce servers 876, the image footprint on the database may bereduced.

The query servers 872 may be used to retrieve information from one ormore file systems. For example, the query system 872 may receiverequests for information from the app servers 888 and then transmitinformation queries to the NFS 896 located outside the pod. The pod 844may share a database instance 890 configured as a multi-tenantenvironment in which different organizations share access to the samedatabase. Additionally, services rendered by the pod 844 may requirevarious hardware and/or software resources. In some embodiments, the ACSservers 880 may control access to data, hardware resources, or softwareresources.

In some embodiments, the batch servers 884 may process batch jobs, whichare used to run tasks at specified times. Thus, the batch servers 884may transmit instructions to other servers, such as the app servers 888,to trigger the batch jobs. In some embodiments, the QFS 892 may be anopen source file system available from Sun Microsystems® of Santa Clara,Calif. The QFS may serve as a rapid-access file system for storing andaccessing information available within the pod 844. The QFS 892 maysupport some volume management capabilities, allowing many disks to begrouped together into a file system. File system metadata can be kept ona separate set of disks, which may be useful for streaming applicationswhere long disk seeks cannot be tolerated. Thus, the QFS system maycommunicate with one or more content search servers 868 and/or indexers894 to identify, retrieve, move, and/or update data stored in thenetwork file systems 896 and/or other storage systems.

In some embodiments, one or more query servers 872 may communicate withthe NFS 896 to retrieve and/or update information stored outside of thepod 844. The NFS 896 may allow servers located in the pod 844 to accessinformation to access files over a network in a manner similar to howlocal storage is accessed. In some embodiments, queries from the queryservers 822 may be transmitted to the NFS 896 via the load balancer 820,which may distribute resource requests over various resources availablein the on-demand service environment. The NFS 896 may also communicatewith the QFS 892 to update the information stored on the NFS 896 and/orto provide information to the QFS 892 for use by servers located withinthe pod 844.

In some embodiments, the pod may include one or more database instances890. The database instance 890 may transmit information to the QFS 892.When information is transmitted to the QFS, it may be available for useby servers within the pod 844 without requiring an additional databasecall. In some embodiments, database information may be transmitted tothe indexer 894. Indexer 894 may provide an index of informationavailable in the database 890 and/or QFS 892. The index information maybe provided to file force servers 876 and/or the QFS 892.

FIG. 9 shows a block diagram of an environment 910 wherein an on-demanddatabase service might be used, in accordance with some embodiments.Environment 910 includes an on-demand database service 916. User system912 may be any machine or system that is used by a user to access adatabase user system. For example, any of user systems 912 can be ahandheld computing system, a mobile phone, a laptop computer, a workstation, and/or a network of computing systems. As illustrated in FIGS.9 and 10, user systems 912 might interact via a network 914 with theon-demand database service 916.

An on-demand database service, such as system 916, is a database systemthat is made available to outside users that do not need to necessarilybe concerned with building and/or maintaining the database system, butinstead may be available for their use when the users need the databasesystem (e.g., on the demand of the users). Some on-demand databaseservices may store information from one or more tenants stored intotables of a common database image to form a multi-tenant database system(MTS). Accordingly, “on-demand database service 916” and “system 916”will be used interchangeably herein. A database image may include one ormore database objects. A relational database management system (RDBMS)or the equivalent may execute storage and retrieval of informationagainst the database object(s). Application platform 918 may be aframework that allows the applications of system 916 to run, such as thehardware and/or software, e.g., the operating system. In animplementation, on-demand database service 916 may include anapplication platform 918 that enables creation, managing and executingone or more applications developed by the provider of the on-demanddatabase service, users accessing the on-demand database service viauser systems 912, or third party application developers accessing theon-demand database service via user systems 912.

One arrangement for elements of system 916 is shown in FIG. 9, includinga network interface 920, application platform 918, tenant data storage922 for tenant data 923, system data storage 924 for system data 925accessible to system 916 and possibly multiple tenants, program code 926for implementing various functions of system 916, and a process space928 for executing MTS system processes and tenant-specific processes,such as running applications as part of an application hosting service.Additional processes that may execute on system 916 include databaseindexing processes.

The users of user systems 912 may differ in their respective capacities,and the capacity of a particular user system 912 might be entirelydetermined by permissions (permission levels) for the current user. Forexample, where a call center agent is using a particular user system 912to interact with system 916, the user system 912 has the capacitiesallotted to that call center agent. However, while an administrator isusing that user system to interact with system 916, that user system hasthe capacities allotted to that administrator. In systems with ahierarchical role model, users at one permission level may have accessto applications, data, and database information accessible by a lowerpermission level user, but may not have access to certain applications,database information, and data accessible by a user at a higherpermission level. Thus, different users may have different capabilitieswith regard to accessing and modifying application and databaseinformation, depending on a user's security or permission level.

Network 914 is any network or combination of networks of devices thatcommunicate with one another. For example, network 914 can be any one orany combination of a LAN (local area network), WAN (wide area network),telephone network, wireless network, point-to-point network, starnetwork, token ring network, hub network, or other appropriateconfiguration. As the most common type of computer network in currentuse is a TCP/IP (Transfer Control Protocol and Internet Protocol)network (e.g., the Internet), that network will be used in many of theexamples herein. However, it should be understood that the networks usedin some embodiments are not so limited, although TCP/IP is a frequentlyimplemented protocol.

User systems 912 might communicate with system 916 using TCP/IP and, ata higher network level, use other common Internet protocols tocommunicate, such as HTTP, FTP, AFS, WAP, etc. In an example where HTTPis used, user system 912 might include an HTTP client commonly referredto as a “browser” for sending and receiving HTTP messages to and from anHTTP server at system 916. Such an HTTP server might be implemented asthe sole network interface between system 916 and network 914, but othertechniques might be used as well or instead. In some embodiments, theinterface between system 916 and network 914 includes load sharingfunctionality, such as round-robin HTTP request distributors to balanceloads and distribute incoming HTTP requests evenly over a plurality ofservers. At least as for the users that are accessing that server, eachof the plurality of servers has access to the MTS′ data; however, otheralternative configurations may be used instead.

In some embodiments, system 916, shown in FIG. 9, implements a web-basedcustomer relationship management (CRM) system. For example, in someembodiments, system 916 includes application servers configured toimplement and execute CRM software applications as well as providerelated data, code, forms, web pages and other information to and fromuser systems 912 and to store to, and retrieve from, a database systemrelated data, objects, and Webpage content. With a multi-tenant system,data for multiple tenants may be stored in the same physical databaseobject, however, tenant data typically is arranged so that data of onetenant is kept logically separate from that of other tenants so that onetenant does not have access to another tenant's data, unless such datais expressly shared. In certain embodiments, system 916 implementsapplications other than, or in addition to, a CRM application. Forexample, system 916 may provide tenant access to multiple hosted(standard and custom) applications. User (or third party developer)applications, which may or may not include CRM, may be supported by theapplication platform 918, which manages creation, storage of theapplications into one or more database objects and executing of theapplications in a virtual machine in the process space of the system916.

Each user system 912 could include a desktop personal computer,workstation, laptop, PDA, cell phone, or any wireless access protocol(WAP) enabled device or any other computing system capable ofinterfacing directly or indirectly to the Internet or other networkconnection. User system 912 typically runs an HTTP client, e.g., abrowsing program, such as Microsoft's Internet Explorer® browser,Mozilla's Firefox® browser, Opera's browser, or a WAP-enabled browser inthe case of a cell phone, PDA or other wireless device, or the like,allowing a user (e.g., subscriber of the multi-tenant database system)of user system 912 to access, process and view information, pages andapplications available to it from system 916 over network 914.

Each user system 912 also typically includes one or more user interfacedevices, such as a keyboard, a mouse, trackball, touch pad, touchscreen, pen or the like, for interacting with a graphical user interface(GUI) provided by the browser on a display (e.g., a monitor screen, LCDdisplay, etc.) in conjunction with pages, forms, applications and otherinformation provided by system 916 or other systems or servers. Forexample, the user interface device can be used to access data andapplications hosted by system 916, and to perform searches on storeddata, and otherwise allow a user to interact with various GUI pages thatmay be presented to a user. As discussed above, embodiments are suitablefor use with the Internet, which refers to a specific globalinternetwork of networks. However, it should be understood that othernetworks can be used instead of the Internet, such as an intranet, anextranet, a virtual private network (VPN), a non-TCP/IP based network,any LAN or WAN or the like.

According to some embodiments, each user system 912 and all of itscomponents are operator configurable using applications, such as abrowser, including computer code run using a central processing unitsuch as an Intel Pentium® processor or the like. Similarly, system 916(and additional instances of an MTS, where more than one is present) andall of their components might be operator configurable usingapplication(s) including computer code to run using a central processingunit such as processor system 917, which may include an Intel Pentium®processor or the like, and/or multiple processor units.

A computer program product implementation includes a machine-readablestorage medium (media) having instructions stored thereon/in which canbe used to program a computer to perform any of the processes of theembodiments described herein. Computer code for operating andconfiguring system 916 to intercommunicate and to process web pages,applications and other data and media content as described herein arepreferably downloaded and stored on a hard disk, but the entire programcode, or portions thereof, may also be stored in any other volatile ornon-volatile memory medium or device, such as a ROM or RAM, or providedon any media capable of storing program code, such as any type ofrotating media including floppy disks, optical discs, digital versatiledisk (DVD), compact disk (CD), microdrive, and magneto-optical disks,and magnetic or optical cards, nanosystems (including molecular memoryICs), or any type of media or device suitable for storing instructionsand/or data. Additionally, the entire program code, or portions thereof,may be transmitted and downloaded from a software source over atransmission medium, e.g., over the Internet, or from another server, ortransmitted over any other conventional network connection (e.g.,extranet, VPN, LAN, etc.) using any communication medium and protocols(e.g., TCP/IP, HTTP, HTTPS, Ethernet, etc.). It will also be appreciatedthat computer code for implementing embodiments can be implemented inany programming language that can be executed on a client system and/orserver or server system such as, for example, C, C++, HTML, any othermarkup language, Java™, JavaScript®, ActiveX®, any other scriptinglanguage, such as VBScript, and many other programming languages as arewell known may be used. (Java™ is a trademark of Sun Microsystems®,Inc.).

According to some embodiments, each system 916 is configured to provideweb pages, forms, applications, data and media content to user (client)systems 912 to support the access by user systems 912 as tenants ofsystem 916. As such, system 916 provides security mechanisms to keepeach tenant's data separate unless the data is shared. If more than oneMTS is used, they may be located in close proximity to one another(e.g., in a server farm located in a single building or campus), or theymay be distributed at locations remote from one another (e.g., one ormore servers located in city A and one or more servers located in cityB). As used herein, each MTS could include logically and/or physicallyconnected servers distributed locally or across one or more geographiclocations. Additionally, the term “server” is meant to include acomputing system, including processing hardware and process space(s),and an associated storage system and database application (e.g., OODBMSor RDBMS) as is well known in the art.

It should also be understood that “server system” and “server” are oftenused interchangeably herein. Similarly, the database object describedherein can be implemented as single databases, a distributed database, acollection of distributed databases, a database with redundant online oroffline backups or other redundancies, etc., and might include adistributed database or storage network and associated processingintelligence.

FIG. 10 also shows a block diagram of environment 910 furtherillustrating system 916 and various interconnections, in accordance withsome embodiments. FIG. 10 shows that user system 912 may includeprocessor system 912A, memory system 912B, input system 912C, and outputsystem 912D. FIG. 10 shows network 914 and system 916. FIG. 10 alsoshows that system 916 may include tenant data storage 922, tenant data923, system data storage 924, system data 925, User Interface (UI) 1030,Application Program Interface (API) 1032, PL/SOQL 1034, save routines1036, application setup mechanism 1038, applications servers10001-1000N, system process space 1002, tenant process spaces 1004,tenant management process space 1010, tenant storage area 1012, userstorage 1014, and application metadata 1016. In other embodiments,environment 910 may not have the same elements as those listed aboveand/or may have other elements instead of, or in addition to, thoselisted above.

User system 912, network 914, system 916, tenant data storage 922, andsystem data storage 924 were discussed above in FIG. 9. Regarding usersystem 912, processor system 912A may be any combination of processors.Memory system 912B may be any combination of one or more memory devices,short term, and/or long term memory. Input system 912C may be anycombination of input devices, such as keyboards, mice, trackballs,scanners, cameras, and/or interfaces to networks. Output system 912D maybe any combination of output devices, such as monitors, printers, and/orinterfaces to networks. As shown by FIG. 10, system 916 may include anetwork interface 920 (of FIG. 9) implemented as a set of HTTPapplication servers 1000, an application platform 918, tenant datastorage 922, and system data storage 924. Also shown is system processspace 1002, including individual tenant process spaces 1004 and a tenantmanagement process space 1010. Each application server 1000 may beconfigured to tenant data storage 922 and the tenant data 923 therein,and system data storage 924 and the system data 925 therein to serverequests of user systems 912. The tenant data 923 might be divided intoindividual tenant storage areas 1012, which can be either a physicalarrangement and/or a logical arrangement of data. Within each tenantstorage area 1012, user storage 1014 and application metadata 1016 mightbe similarly allocated for each user. For example, a copy of a user'smost recently used (MRU) items might be stored to user storage 1014.Similarly, a copy of MRU items for an entire organization that is atenant might be stored to tenant storage area 1012. A UI 1030 provides auser interface and an API 1032 provides an application programmerinterface to system 916 resident processes to users and/or developers atuser systems 912. The tenant data and the system data may be stored invarious databases, such as Oracle™ databases.

Application platform 918 includes an application setup mechanism 1038that supports application developers' creation and management ofapplications, which may be saved as metadata into tenant data storage922 by save routines 1036 for execution by subscribers as tenant processspaces 1004 managed by tenant management process 1010 for example.Invocations to such applications may be coded using PL/SOQL 34 thatprovides a programming language style interface extension to API 1032. Adetailed description of some PL/SOQL language embodiments is discussedin commonly assigned U.S. Pat. No. 7,730,478, titled METHOD AND SYSTEMFOR ALLOWING ACCESS TO DEVELOPED APPLICATIONS VIA A MULTI-TENANTON-DEMAND DATABASE SERVICE, by Craig Weissman, filed Sep. 21, 4007,which is hereby incorporated by reference in its entirety and for allpurposes. Invocations to applications may be detected by systemprocesses, which manage retrieving application metadata 1016 for thesubscriber making the invocation and executing the metadata as anapplication in a virtual machine.

Each application server 1000 may be communicably coupled to databasesystems, e.g., having access to system data 925 and tenant data 923, viaa different network connection. For example, one application server10001 might be coupled via the network 914 (e.g., the Internet), anotherapplication server 1000N-1 might be coupled via a direct network link,and another application server 1000N might be coupled by yet a differentnetwork connection. Transfer Control Protocol and Internet Protocol(TCP/IP) are typical protocols for communicating between applicationservers 1000 and the database system. However, other transport protocolsmay be used to optimize the system depending on the network interconnectused.

In certain embodiments, each application server 1000 is configured tohandle requests for any user associated with any organization that is atenant. Because it is desirable to be able to add and remove applicationservers from the server pool at any time for any reason, there ispreferably no server affinity for a user and/or organization to aspecific application server 1000. In some embodiments, therefore, aninterface system implementing a load balancing function (e.g., an F5Big-IP load balancer) is communicably coupled between the applicationservers 1000 and the user systems 912 to distribute requests to theapplication servers 1000. In some embodiments, the load balancer uses aleast connections algorithm to route user requests to the applicationservers 1000. Other examples of load balancing algorithms, such as roundrobin and observed response time, also can be used. For example, incertain embodiments, three consecutive requests from the same user couldhit three different application servers 1000, and three requests fromdifferent users could hit the same application server 1000. In thismanner, system 916 is multi-tenant, wherein system 916 handles storageof, and access to, different objects, data and applications acrossdisparate users and organizations.

As an example of storage, one tenant might be a company that employs asales force where each call center agent uses system 916 to manage theirsales process. Thus, a user might maintain contact data, leads data,customer follow-up data, performance data, goals and progress data,etc., all applicable to that user's personal sales process (e.g., intenant data storage 922). In an example of a MTS arrangement, since allof the data and the applications to access, view, modify, report,transmit, calculate, etc., can be maintained and accessed by a usersystem having nothing more than network access, the user can manage hisor her sales efforts and cycles from any of many different user systems.For example, if a call center agent is visiting a customer and thecustomer has Internet access in their lobby, the call center agent canobtain critical updates as to that customer while waiting for thecustomer to arrive in the lobby.

While each user's data might be separate from other users' dataregardless of the employers of each user, some data might beorganization-wide data shared or accessible by a plurality of users orall of the users for a given organization that is a tenant. Thus, theremight be some data structures managed by system 916 that are allocatedat the tenant level while other data structures might be managed at theuser level. Because an MTS might support multiple tenants includingpossible competitors, the MTS should have security protocols that keepdata, applications, and application use separate. Also, because manytenants may opt for access to an MTS rather than maintain their ownsystem, redundancy, up-time, and backup are additional functions thatmay be implemented in the MTS. In addition to user-specific data andtenant specific data, system 916 might also maintain system level datausable by multiple tenants or other data. Such system level data mightinclude industry reports, news, postings, and the like that are sharableamong tenants.

In certain embodiments, user systems 912 (which may be clientmachines/systems) communicate with application servers 1000 to requestand update system-level and tenant-level data from system 916 that mayrequire sending one or more queries to tenant data storage 922 and/orsystem data storage 924. System 916 (e.g., an application server 1000 insystem 916) automatically generates one or more SQL statements (e.g.,SQL queries) that are designed to access the desired information. Systemdata storage 924 may generate query plans to access the requested datafrom the database.

Each database can generally be viewed as a collection of objects, suchas a set of logical tables, containing data fitted into predefinedcategories. A “table” is one representation of a data object, and may beused herein to simplify the conceptual description of objects and customobjects according to some embodiments. It should be understood that“table” and “object” may be used interchangeably herein. Each tablegenerally contains one or more data categories logically arranged ascolumns or fields in a viewable schema. Each row or record of a tablecontains an instance of data for each category defined by the fields.For example, a CRM database may include a table that describes acustomer with fields for basic contact information such as name,address, phone number, fax number, etc. Another table might describe apurchase order, including fields for information such as customer,product, sale price, date, etc. In some multi-tenant database systems,standard entity tables might be provided for use by all tenants. For CRMdatabase applications, such standard entities might include tables foraccount, contact, lead, and opportunity data, each containingpre-defined fields. It should be understood that the word “entity” mayalso be used interchangeably herein with “object” and “table”.

In some multi-tenant database systems, tenants may be allowed to createand store custom objects, or they may be allowed to customize standardentities or objects, for example by creating custom fields for standardobjects, including custom index fields. U.S. Pat. No. 7,779,039, titledCUSTOM ENTITIES AND FIELDS IN A MULTI-TENANT DATABASE SYSTEM, byWeissman, et al., and which is hereby incorporated by reference in itsentirety and for all purposes, teaches systems and methods for creatingcustom objects as well as customizing standard objects in a multi-tenantdatabase system. In some embodiments, for example, all custom entitydata rows are stored in a single multi-tenant physical table, which maycontain multiple logical tables per organization. In some embodiments,multiple “tables” for a single customer may actually be stored in onelarge table and/or in the same table as the data of other customers.

These and other aspects of the disclosure may be implemented by varioustypes of hardware, software, firmware, etc. For example, some featuresof the disclosure may be implemented, at least in part, bymachine-readable media that include program instructions, stateinformation, etc., for performing various operations described herein.Examples of program instructions include both machine code, such asproduced by a compiler, and files containing higher-level code that maybe executed by the computer using an interpreter. Examples ofmachine-readable media include, but are not limited to, magnetic mediasuch as hard disks, floppy disks, and magnetic tape; optical media suchas CD-ROM disks; magneto-optical media; and hardware devices that arespecially configured to store and perform program instructions, such asread-only memory devices (“ROM”) and random access memory (“RAM”).

While one or more embodiments and techniques are described withreference to an implementation in which a service cloud console isimplemented in a system having an application server providing a frontend for an on-demand database service capable of supporting multipletenants, the one or more embodiments and techniques are not limited tomulti-tenant databases nor deployment on application servers.Embodiments may be practiced using other database architectures, i.e.,ORACLE®, DB2® by IBM and the like without departing from the scope ofthe embodiments claimed.

Any of the above embodiments may be used alone or together with oneanother in any combination. Although various embodiments may have beenmotivated by various deficiencies with the prior art, which may bediscussed or alluded to in one or more places in the specification, theembodiments do not necessarily address any of these deficiencies. Inother words, different embodiments may address different deficienciesthat may be discussed in the specification. Some embodiments may onlypartially address some deficiencies or just one deficiency that may bediscussed in the specification, and some embodiments may not address anyof these deficiencies.

While various embodiments have been described herein, it should beunderstood that they have been presented by way of example only, and notlimitation. Thus, the breadth and scope of the present applicationshould not be limited by any of the embodiments described herein, butshould be defined only in accordance with the following andlater-submitted claims and their equivalents.

What is claimed is:
 1. A computer-implemented method to merge nodes inhierarchies, the method comprising: receiving, by a database system, arequest to merge a first node in a first hierarchy of a plurality ofnodes into a second node, the first node in the first hierarchy havingchild nodes; determining, by the database system, whether the mergerequest violates each of a plurality of constraints, the plurality ofconstraints comprising circular dependency of nodes, deleted node andordering of nodes; merging, by the database system, the first node intothe second node in response to a determination that the merge requestdoes not violate each of the plurality of constraints; and re-parenting,by the database system, the child nodes of the first node in the firsthierarchy of nodes to the second node in response to the merging of thefirst node into the second node, the child nodes of the first nodebecoming the children of the second node.
 2. The method of claim 1,wherein the merge request violates the ordering of nodes constraint whenthe second node is a descendant of the first node.
 3. The method ofclaim 2, wherein the merge request violates the deleted node constraintwhen the first node or the second node is a deleted node.
 4. The methodof claim 3, wherein, based on the merge request including a new parentidentification (ID) for the second node, the merge request violates theordering of nodes constraint when a node associated with the new parentID is a descendant of the second node.
 5. The method of claim 4, whereinthe merge request violates the deleted node constraint when the nodeassociated with the new parent ID is a deleted node.
 6. The method ofclaim 5, wherein the merge request violates the circular dependencyconstraint when the first node or the second node is associated with ahierarchy having circular dependency or when said merging the first nodeto the second node generates a hierarchy having circular dependency. 7.The method of claim 6, wherein said re-parenting the child nodes of thefirst node to the second node includes re-parenting a soft delete childnode of the first node to the second node.
 8. The method of claim 7,further comprising deleting, by the database system, the first nodebased on the merge request being allowed to proceed.
 9. An apparatuscomprising: one or more processors; and a non-transitory computerreadable medium storing a plurality of instructions, which whenexecuted, cause the one or more processors to: receive a request tomerge a first node in a first hierarchy of a plurality of nodes into asecond node, the first node in the first hierarchy having child nodes;determine whether the merge request violates each of a plurality ofconstraints, the plurality of constraints comprising circular dependencyof nodes, deleted node and ordering of nodes; and re-parent, in responseto a determination that the merge request does not violate each of theplurality of constraints, the child nodes of the first node in the firsthierarchy of nodes to the second node in response to the merging of thefirst node into the second node.
 10. The apparatus of claim 9, whereinthe merge request violates the ordering of nodes constraint when thesecond node is a descendant of the first node.
 11. The apparatus ofclaim 10, wherein the merge request violates the deleted node constraintwhen the first node or the second node is a deleted node.
 12. Theapparatus of claim 11, wherein the merge request violates the orderingof nodes constraint when the merge request includes a new parentidentification (ID) for the second node, and wherein a node associatedwith the new parent ID is a descendant of the second node.
 13. Theapparatus of claim 12, wherein the merge request violates the deletednode constraint when the node associated with the new parent ID is adeleted node.
 14. The apparatus of claim 13, wherein the merge requestviolates the circular dependency constraint when the first node or thesecond node is associated with a hierarchy having circular dependency orwhen said merging the first node to the second node generates ahierarchy having circular dependency.
 15. The apparatus of claim 14,wherein said instructions to re-parent the child nodes of the first nodeto the second node include instructions to re-parent a soft delete childnode of the first node to the second node.
 16. The apparatus of claim15, further comprising instructions, which when executed, cause the oneor more processors to delete the first node based on the merge requestbeing allowed to proceed.
 17. A computer program product comprisingcomputer-readable program code to be executed by one or more processorswhen retrieved from a non-transitory computer-readable medium, theprogram code including instructions to: receive a request to merge afirst node in a first hierarchy of a plurality of nodes into a secondnode, the first node in the first hierarchy having child nodes;determine whether the merge request violates each of a plurality ofconstraints, the plurality of constraints comprising circular dependencyof nodes, deleted node and ordering of nodes; and re-parent, in responseto a determination that the merge request does not violate each of theplurality of constraints, the child nodes of the first node in the firsthierarchy of nodes to the second node in response to the merging of thefirst node into the second node.
 18. The computer program product ofclaim 17, wherein the merge request violates the ordering of nodesconstraint when the second node is a descendant of the first node. 19.The computer program product of claim 18, wherein the merge requestviolates the deleted node constraint when the first node or the secondnode is a deleted node.
 20. The computer program product of claim 19,wherein the merge request violates the circular dependency constraintwhen the merge request includes a new parent identification (ID) for thesecond node, and wherein a node associated with the new parent ID is adescendant of the second node.
 21. The computer program product of claim20, wherein the merge request violates the deleted node constraint whenthe node associated with the new parent ID is a deleted node.
 22. Thecomputer program product of claim 21, wherein the merge request violatesthe circular dependency constraint when the first node or the secondnode is associated with a hierarchy having circular dependency or whensaid merging the first node to the second node generates a hierarchyhaving circular dependency.
 23. The computer program product of claim22, wherein the program code to re-parent the child nodes of the firstnode to the second node includes program code to re-parent a soft deletechild node of the first node to the second node.
 24. The computerprogram product of claim 23, the program code including furtherinstructions to delete the first node based on the merge request beingallowed to proceed.